home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 294 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: bs@research.att.com
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Observations on templates
  5. Date: 5 Feb 1996 23:30:07 GMT
  6. Organization: ?
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <199602052224.PAA26224@ncar.ucar.EDU>
  9. NNTP-Posting-Host: taumet.eng.sun.com
  10. Content-Type: text
  11. Content-Length: 2177
  12. X-Lines: 52
  13. Originator: clamage@taumet
  14.  
  15. Article 15951 of comp.std.c++:
  16.  
  17.  
  18. John Max Skaller <maxtal@suphys.physics.su.oz.au> writes
  19.  
  20.  > Eugene Radchenko wrote:
  21.  > > Why don't use, for instance, cast_d instead od
  22.  > > dynamic_cast (ugh). 
  23.  > 
  24.  >       This is quite deliberate. Bjarne dislikes casts. So do I.
  25.  > He didn't invent new style casts (and RTTI) for your convenience, 
  26.  > he invented them to make sure no one else did.
  27.  
  28. Hmmm. That is a bit strong.  I find casts of all sorts overused.
  29. There is almost always a better way to write code than one that
  30. involves an explicit type conversion.
  31.  
  32. However, IMO some casts are essential. Some uses of dynamic_cast are
  33. examples of code that cannot be written conveniently without help
  34. from the language; see D&E for examples. Please remember that you
  35. don't always have source code available so that you can modify classes
  36. to avoid the need for RTTI,and even where it is available you sometimes
  37. prefer not to touch it to minimize maintainance.
  38.  
  39.  >  Long names were deliberately chosen to discourage use of casts.
  40.  
  41. That, to make emphasize the seriousness of the operation done with
  42. a cast, and to make sure that casts are relatively easy to find in
  43. a program (``to make casts stand out like a sore thumb'').
  44.  
  45. One think I have come to dislike about C-style casts is that they
  46. are almost invisible in code. Since they don't look like much,
  47. people get fooled into thinking they don't do much. Also, (T)e is a
  48. shorthand for several logically different operations (type conversion,
  49. reinterpretation of a bitpattern, casting away const, class hierarchy
  50. navigation) and you need to know the type T, the type of e, and the
  51. rules of C++ rather well to know which.
  52.  
  53.     - Bjarne
  54. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  55.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  56.   summarized in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  57. ]
  58.